home *** CD-ROM | disk | FTP | other *** search
- // KillTemporaryItems.c
- // 17 March 2000
- // d.c.oshel
- //
- // Happy St. Patrick's Day
- //
- // This moves non-busy items in OS 9's broken "Temporary Items" folder to the desktop.
- //
- // CAUTION: ABSOLUTELY NO WARRANTY OR SUPPORT -
- // USE THIS UTILITY AT YOUR OWN RISK AND DISCRETION!
- //
- // Changes:
- // v1.0b2 - 18 mar 2000 dco - fixed loop error, only moving one file at a time;
- // removed beep, should be a noop if nothing happens
-
-
- /*------------------------------------------------------------------------------
- #
- # Macintosh Developer Technical Support
- #
- # Simple Color QuickDraw Sample Application
- #
- # SillyBalls
- #
- # SillyBalls.c - C Source
- #
- # Copyright © 1988 Apple Computer, Inc.
- # All rights reserved.
- #
- # Versions: 1.0 8/88
- #
- # Components: SillyBalls.c August 1, 1988
- # SillyBalls.make August 1, 1988
- #
- # This is a very simple sample program that demonstrates how to use Color
- # QuickDraw. It is about two pages of code, and does nothing more than open
- # a color window and draw randomly colored ovals in the window.
- #
- # The purpose is to show how to get some initial results with Color QuickDraw.
- # It is a complete program and is very short to be as clear as possible.
- #
- # It does not have an Event Loop. It is not fully functional in the sense that
- # it does not do all the things you would expect a well behaved Macintosh
- # program to do, like size the window naturally, have an event loop, use menus,
- # etc.
- #
- # See Sample and TESample for the general structure and MultiFinder techniques that
- # we recommend that you use when building a new application.
- #
- ------------------------------------------------------------------------------*/
-
-
- // Version 1.0: 6/2/88
- // 7/20/88 DJB Converted to C
- //
- // purpose To demonstrate a simple color App using Color QuickDraw.
- // It draws colored balls in a color window, then uses colored
- // text inverted in the ball. The ball location and color is Random.
- //
- // This program was written by Bo3b Johnson, 1/88.
- //
- // The inverted Bob text was a Skippy Blair special concept,
- // kept for obvious aesthetic reasons.
-
- //MW -cut out some other program descriptions.-
-
- //MW ** Metrowerks note **
- // All changed code by Metrowerks is commented by "//MW".
- // There is one type of modification to the original source:
- // • Added argument type and return type to function definitions.
- // In order to pass with extended error checking on.
- //
- // 8/31/93 JA
-
-
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <SegLoad.h>
- #include <Sound.h>
-
-
- /* Prototypes */
- void Initialize(void);
- void KillTemporaryItems( void );
-
-
- //
- // Main body of program SillyBalls
- //
-
- //MW specified argument and return type.
- int main(void)
- {
- Initialize();
-
- KillTemporaryItems();
-
- return 0;
- }
-
- //
- // Initialize everything for the program, make sure we can run
- //
-
- //MW specified argument and return type.
- void Initialize(void)
- {
- OSErr error;
- SysEnvRec theWorld;
-
- //
- // Test the computer to be sure we can do color.
- // If not we would crash, which would be bad.
- // If we can’t run, just beep and exit.
- //
-
- error = SysEnvirons(1, &theWorld);
- if (theWorld.hasColorQD == false) {
- SysBeep(50);
- ExitToShell(); /* If no color QD, we must leave. */
- }
-
- /* Initialize all the needed managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- }
-
-
- void KillTemporaryItems( void )
- {
- CInfoPBRec pb;
- CMovePBRec mv;
-
- short foundVRefNum, desktopVRefNum;
- long foundDirID, desktopDirID, newDir = 0;
- Str255 pstr;
- FSSpec fs;
-
- OSErr err = FindFolder(kOnSystemDisk,
- kTemporaryFolderType,
- kDontCreateFolder,
- &foundVRefNum,
- &foundDirID); /* IM VI chap. 9 pg 44 */
-
- if ( err == noErr )
- {
- err = FindFolder( kOnSystemDisk,
- kDesktopFolderType,
- kDontCreateFolder,
- &desktopVRefNum,
- &desktopDirID);
-
- while (1)
- {
- pstr[0] = 0;
-
- pb.dirInfo.ioNamePtr = pstr;
- pb.dirInfo.ioVRefNum = foundVRefNum;
- pb.dirInfo.ioDrDirID = foundDirID;
- pb.dirInfo.ioFDirIndex = 1; // always move the first item in the folder
-
- err = PBGetCatInfoSync(&pb);
-
- if ( err ) // exit condition is fnfErr (or any other error)
- break;
-
- if (( pb.dirInfo.ioFlAttrib & 0x80 ) != 0x80 ) // if file (or folder) is not busy
- {
- if ( !newDir )
- {
- err = FSMakeFSSpec( desktopVRefNum, desktopDirID, "\pStuff OS 9 left lying around", &fs );
-
- if ( err == noErr ) // folder already there? quit, can't do anything
- break;
-
- else if ( err == fnfErr ) // we hope it's not!
- err = FSpDirCreate(&fs,smSystemScript,&newDir);
- }
-
- mv.ioNamePtr = pstr;
- mv.ioDirID = foundDirID;
- mv.ioVRefNum = foundVRefNum;
- mv.ioNewName = nil;
- mv.ioNewDirID = newDir;
-
- err = PBCatMoveSync( &mv );
- }
- }
- }
- }
-
-